package com.zju.DoctorGo.controller;

import com.zju.DoctorGo.dto.ScheduleFilterDTO;
import com.zju.DoctorGo.entity.Schedule;
import com.zju.DoctorGo.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/schedule")
public class ScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    @PostMapping
    public ResponseEntity<?> getSchedules(@RequestBody ScheduleFilterDTO filter) {
        List<Schedule> schedules = scheduleService.getSchedules(filter);
        return ResponseEntity.ok(schedules);
    }

    @PostMapping("/add")
    public ResponseEntity<?> addSchedule(@RequestBody Schedule schedule) {
        scheduleService.addSchedule(schedule);
        return ResponseEntity.ok().body("Schedule added successfully");
    }

    @PostMapping("/addBatch")
    public ResponseEntity<?> addSchedules(@RequestBody List<Schedule> schedules) {
        for (Schedule schedule : schedules) { scheduleService.addSchedule(schedule); }
        return ResponseEntity.ok().body("Schedules added successfully");
    }

    @PostMapping("/delete")
    public ResponseEntity<?> deleteSchedules(@RequestBody ScheduleFilterDTO filter) {
        scheduleService.deleteSchedules(filter);
        return ResponseEntity.ok().body("Schedules deleted successfully");
    }

    @PostMapping("/update")
    public ResponseEntity<?> updateSchedule(@RequestBody Schedule schedule) {
        scheduleService.updateSchedule(schedule);
        return ResponseEntity.ok().body("Schedule updated successfully");
    }
}
